Skip to content

Conversation

shaikenov
Copy link

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR adds a new metric to the exported prometheus metrics list: LongestNodeScaleDownTime

We want to track all the nodes that were marked as unneeded, but were unprocessed during the ScaleDown. If a node was unneeded, but unprocessed multiple times consecutively, we store only the earliest time it happened. The difference between the current time and the earliest time among all unprocessed nodes will give the longest time. This time can give us an indication of possible throttling and helps to better monitor what happens during ScaleDown.

Which issue(s) this PR fixes:

None

Special notes for your reviewer: this is a draft PR, work is still in progress

Does this PR introduce a user-facing change?

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

None

@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Oct 5, 2025
Copy link

linux-foundation-easycla bot commented Oct 5, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: shaikenov / name: Olzhas Shaikenov (86a98d1)

@k8s-ci-robot
Copy link
Contributor

Welcome @shaikenov!

It looks like this is your first PR to kubernetes/autoscaler 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/autoscaler has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Oct 5, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @shaikenov. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Oct 5, 2025
Copy link

@kada2004 kada2004 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very good

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: kada2004, shaikenov
Once this PR has been reviewed and has the lgtm label, please assign aleksandra-malinowska for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@shaikenov shaikenov force-pushed the shaikenov-scaledown-unprocessed-node-tracking branch from b9e7969 to 86a98d1 Compare October 6, 2025 11:40
}

type longestNodeScaleDownTime struct {
defaultTime time.Time

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's maybe rename it to sth more meaningful: evalTime, lastEvalTime, ...?

Comment on lines +481 to +482
l.nodeNamesWithTimeStamps = make(map[string]time.Time)
metrics.ObserveLongestNodeScaleDownTime(0)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should report the biggest time (if there were any carry over from the previous loop) before clearing it.
Also l.defaultTime should be updated here.
Please add a unit test for this scenario.

Comment on lines +1060 to +1080
nodes := make([]*apiv1.Node, tc.nodes)
for i := 0; i < tc.nodes; i++ {
nodes[i] = BuildTestNode(fmt.Sprintf("n%d", i), 1000, 10)
}
provider := testprovider.NewTestCloudProviderBuilder().Build()
provider.AddNodeGroup("ng1", 0, 0, 0)
for _, node := range nodes {
provider.AddNode("ng1", node)
}
context, err := NewScaleTestAutoscalingContext(config.AutoscalingOptions{
NodeGroupDefaults: config.NodeGroupAutoscalingOptions{
ScaleDownUnneededTime: 1 * time.Minute,
},
ScaleDownSimulationTimeout: 1 * time.Hour,
MaxScaleDownParallelism: 10,
LongestNodeScaleDownTimeTrackerEnabled: true,
}, &fake.Clientset{}, nil, provider, nil, nil)
assert.NoError(t, err)
clustersnapshot.InitializeClusterSnapshotOrDie(t, context.ClusterSnapshot, nodes, nil)
deleteOptions := options.NodeDeleteOptions{}
p := New(&context, processorstest.NewTestProcessors(&context), deleteOptions, nil)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be easier to just create instance with newLongestNodeScaleDownTime()?

var timestamp time.Time

// take nodes "n0" - "n3" as unneeded
unneededNodeNames := tc.unneededNodes1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need unneededNodeNames variable?

// if a node is already in nodeNamesWithTimeStamps copy the last value
valueFromPrevIter := l.get(nodeName)
newNodes[nodeName] = valueFromPrevIter
if minimumTime.Compare(valueFromPrevIter) > 0 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: From what I see Compare() is not used here. Please use Before() or After().

return
}
newNodes := make(map[string]time.Time, len(nodeNames))
l.defaultTime = currentTime

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you override l.defaultTime too early.

Let's imagine very simple scenario with one node:

time unneeded reportedTime nodeNamesWithTimeStamps
t [] 0
t+1 [n1] 1 n1 : t
t+2 [n1] 2 n1 : t
t+3 [] 3
t+4 [] 0

Seems like with your implementation you would at t +1 save n1: t+1 and report 0.

Comment on lines +432 to +433
Name: "longest_scale_down_eval",
Help: "Longest node evaluation time during ScaleDown.",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a unit as suffix (eg. like function_duration_seconds).
Have you checked what buckets are used by default and if they are fine for this use case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cluster-autoscaler cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants